﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Modules.DataDictionary;
using Bingosoft.Web.Utils;

namespace HHMMS.UI.Modules.PlanManager
{
    public partial class DistributePlanList : System.Web.UI.Page
    {
        private StorageService storageService = new StorageService();
        protected bool isPSS = false;
        protected bool isAdmin = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            isPSS = Bingosoft.Security.SecurityContext.User.HasRole("4CA8176D-6E13-4CFC-BF9C-F1DBDCCD03C7");//配送人角色ID
            isAdmin = Bingosoft.Security.SecurityContext.User.HasRole("AD6754E3-B4D8-412D-9CD9-DC19DC42EBEA");//系统管理员角色ID
        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            this.GridSearch.Search();
        }

        protected void Clone(object sender, EventArgs e)
        {
            if (isAdmin)
            {
                storageService.CloneDistributePlan(((System.Web.UI.WebControls.ImageButton)(sender)).CommandName);
                ScriptHelper.Alert(this, "克隆成功！");
                this.GridSearch.Refresh();
            }
            else
            {
                ScriptHelper.Alert(this, "对不起，您不是管理员，您没有克隆权限！");
            }
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            this.GridSearch.Refresh();
        }

        protected void DeleteDictionaryItem(object sender, EventArgs e)
        {
            if (isAdmin)
            {
                var _sender = sender as ImageButton;
                String Id = _sender.Attributes["_KeyId"];

                this.storageService.DeleteDataPartItem(Id);

                RefreshGrid(sender, e);
            }
            else
            {
                ScriptHelper.Alert(this, "对不起，您不是管理员，您没有删除权限！");
            }
        }

        protected void SmartGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //ImageButton enableImgBtn = e.Row.FindControl("EnableImageButton") as ImageButton;
                //ImageButton disableImgBtn = e.Row.FindControl("DisableImageButton") as ImageButton;
                //string status = enableImgBtn.Attributes["_STATUS"];
                //if ("enabled".Equals(status))
                //{
                //    enableImgBtn.Visible = false;
                //    disableImgBtn.Visible = true;
                //}
                //else
                //{
                //    enableImgBtn.Visible = true;
                //    disableImgBtn.Visible = false;
                //}
            }
        }
        protected void LinkButtonExport_Click(object sender, EventArgs e)
        {
            this.SmartGridView1.SaveAsXls(string.Format("配送计划清单{0:yyyyMM}.xls", DateTime.Now), true, this.SmartGridView1.Columns.Count - 1);
        }
    }
}